<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="layout">

<div layout:fragment="body">
    <form id="channel-form" method="post" th:action="@{/channel/form}" th:object="${channel}" liger="{type : 'ligerForm'}">
        <input type="hidden" th:field="*{id}"/>
        <input type="hidden" th:field="*{userId}"/>
        <input type="hidden" th:field="*{no}"/>
        <input type="hidden" th:field="*{pid}"/>
        <input th:if="${isParent}" type="hidden" th:field="*{type}"/>
        <input th:if="!${#strings.isEmpty(channel.id)}" type="hidden"  th:field="*{code}"/>
        <table class="l-table-form">
            <tr th:if="${#strings.isEmpty(channel.id)}">
                <th th:text="#{channel.code}"></th>
                <td>
                    <table class="no_border_table">
                        <tr>
                            <td>
                                <input id="code" type="text" ltype="text" th:placeholder="#{channel.code}" th:field="*{code}" validate="{required:true}"/>
                            </td>
                            <td>
                                <a id="autoCode" href="javascript:;" class="l-link-button"><img alt="" src="/js/ligerUI/skins/icons/prev.gif" />自动生成</a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr th:if="!${#strings.isEmpty(channel.id)}">
                <th th:text="#{channel.code}"></th>
                <td th:text="${channel.code}"></td>
            </tr>
            <tr>
                <th th:text="#{channel.name}"></th>
                <td><input type="text" ltype="text" th:placeholder="#{channel.name}" th:field="*{name}" validate="{required:true}"/></td>
            </tr>
            <tr th:if="!${isParent}">
                <th th:text="#{channel.type}"></th>
                <td>
                    <input type="text" th:placeholder="#{channel.type}" data-width="178" liger="{type:'comboBox',valueFieldID:'type',configCode:'CHANNEL_TYPE_ENUM'}" validate="{required:true}"/>
                    <input th:field="*{type}" style="display: none;">
                </td>
            </tr>
            <tr>
                <th th:text="#{channel.mobile}"></th>
                <td><input type="text" ltype="text" th:placeholder="#{channel.mobile}" th:field="*{mobile}"/></td>
            </tr>
        </table>
    </form>
</div>

<script type="text/javascript" layout:fragment="script">/*<![CDATA[*/
var $form;
$(function() {
    $("#autoCode").on("click", function() {
        $.ajax({
            url: '/channel/getAutoCode',
            type: "GET",
            success: function (reply) {
                if (reply != null) {
                    $("#code").val(reply.data);
                }
            }
        });
        return false;
    });
});
/*]]>*/</script>

</html>
